package com.ivy.irublesson.GetConnection;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * Created by Administrator on 2018/1/12.
 */

public class Login {
  //  public static String cookie;
    private static ByteArrayOutputStream stream; ;

    public static ByteArrayOutputStream getStream() {
        return stream;
    }

    public static String login(String path , String referer){

        String cookie = null;

        try {

            URL url=new URL(path);
            HttpURLConnection con=(HttpURLConnection)url.openConnection();
            con.setRequestMethod("GET");
            con.setDoOutput(true);
            con.setDoInput(true);
            con.setRequestProperty("Referer", referer);
            InputStream in=con.getInputStream();
            cookie = con.getHeaderField("Set-Cookie");
            Log.i("Cookie........" , cookie);

            stream = new ByteArrayOutputStream();
            int len = 0;
            byte[] buffer = new byte[1024];
            while((len=in.read(buffer))!=-1){
                stream.write(buffer, 0, len);
            }

            in.close();
            con.disconnect();

            return cookie;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

    }
}
